﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;

/// <summary>
/// Summary description for Controls
/// </summary>
namespace WB.Controls
{
    public class FControls
    {
        public string Id { get; set; }
        public string Path { get; set; }
        public string Description { get; set; }

        public FControls()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public bool LoadControl(string id)
        {
            string xmlpath = HttpContext.Current.Server.MapPath("~/App_Data/controls.xml");
            XElement xDoc = XElement.Load(xmlpath);
            var query = (from ctr in xDoc.Descendants("control")
                         where ctr.Attribute("id").Value == id
                         select new FControls
                         {
                             Id = ctr.Attribute("id").Value,
                             Path = ctr.Attribute("path").Value,
                             Description = ctr.Attribute("descript").Value
                         }).AsEnumerable();
            if (query.Count() > 0)
            {
                var item = query.Single();
                Id = item.Id;
                Path = item.Path;
                Description = item.Description;
                return true;
            }
            return false;
        }
    }
}